<?php
header('Content-Type: application/json; charset=utf-8');
include("./api.inc.php");
require './config.php';


// 更新授权表中的VisitorIp字段,只判断大于两小时的
$row = $DB->query("UPDATE auth_kms SET VisitorIp = NULL AND SET activation = NULL WHERE activation < NOW() - INTERVAL 2 HOUR");
if ($row) {
    $arr = array("code" => 200, "msg" => "用户IP地址授权清理成功");
    echo(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
} else {
    $arr = array("code" => 201, "msg" => "用户IP地址授权清理失败");
    exit(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
}

// 清理过期的auth_kms记录
$row = $DB->query("DELETE FROM auth_kms WHERE Expiration < NOW()");
if ($row) {
    $arr = array("code" => 200, "msg" => "过期卡密清理成功");
    echo(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
} else {
    $arr = array("code" => 201, "msg" => "过期卡密清理失败");
    exit(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
}

// 清理过期的auth_km记录
$row = $DB->query("DELETE FROM auth_km WHERE Expiration < NOW()");
if ($row) {
    $arr = array("code" => 200, "msg" => "过期卡密清理成功");
    echo(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
} else {
    $arr = array("code" => 201, "msg" => "过期卡密清理失败");
    exit(json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
}